<?php
require_once("../includes/func.php");
require_once("../includes/themes/" . $myTheme . "/head.php");


echo '<div class="homebody"><div class="center">';
echo '<h2>Добавление новости</h2>';

$act = intval($_GET['act']);
switch ($act) {
default:
	?>
	<div id="login">
		<form method="post" action="<?php echo HOME . MYDIR; ?>apanel/?act=99" >
			<div id="login_form">
				<input type="text" name="username" size="30" maxlength="100" value="" /> Имя<br />
				<input type="password" name="password" size="30" maxlength="100" value="" /> Пороль<br />
			</div><br />
			<input type="submit" name="submit" class="submit-botton" value=" Войти " />
		</form>
	</div>
	<?php
	break;
	
case 99:
	$auth = new Auth;
	$cheked = $auth -> check($_POST['username'], $_POST['password'], "AND `stat` = 1");
	if (!$cheked) {
		echo '<div class="message">'. $auth -> errors .'</div><br />';
		break;
	}
	
	echo '<div id="login">';
		echo '<div id="login_form">';
			echo '<a href="'. HOME . MYDIR .'apanel/?act=1">Добавить новость</a><br />';
			echo '<a href="'. HOME . MYDIR .'apanel/news.php">Управление новостями</a><br />';
			echo '<a href="'. HOME . MYDIR .'apanel/comments.php">Управление комментариями</a><br />';
		echo '</div>';
	echo '</div>';
	
	break;
case 1: //Добавляем новость
	
	?>
	<script type="text/javascript" src="../includes/modules/wysiwyg/tiny_mce.js"></script>
	<script type="text/javascript">
	tinyMCE.init({
        // General options
        mode : "textareas",
        theme : "advanced",
        plugins : "pagebreak,style,layer,table,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,

        // Skin options
        skin : "o2k7",
        skin_variant : "silver",

        // Example content CSS (should be your site CSS)
        content_css : "/includes/themes/minimum/meta.css",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "js/template_list.js",
        external_link_list_url : "js/link_list.js",
        external_image_list_url : "js/image_list.js",
        media_external_list_url : "js/media_list.js",

        // Replace values for the template plugin
        template_replace_values : {
                username : "Some User",
                staffid : "991234"
        }
	});
	
	</script>

	
	
	<form method="post" action="<?php echo HOME . MYDIR; ?>apanel/?act=2" >
		<b>Тема</b><br /><input type="text" onKeyUp="convert2EN();" onChange="convert2EN();" id="postTitle" name="title" size="76" value="" /><br />
		<b>Чпу</b><br /><input type="text" id="url" name="url" size="76" value="" /><br />
		<b>Метки</b> (через запятую)<br /><input type="text" name="tags" size="76" value="" /><br />
		<b>Полный текст</b><br /><textarea rows="20" cols="100" name="message"></textarea>
		<br/><input type="submit" name="submit" class="submit-botton" value="Отправить" />
	</form>
	<script type="text/javascript">
		var rusChars = new Array('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ч','ц','ш','щ','э','ю','\я','ы','ъ','ь', ' ', '\'', '\"', '\#', '\$', '\%', '\&', '\*', '\,', '\:', '\;', '\<', '\>', '\?', '\[', '\]', '\^', '\{', '\}', '\|', '\!', '\@', '\(', '\)', '\-', '\=', '\+', '\/', '\\', '/ +/g');
		var transChars = new Array('a','b','v','g','d','e','jo','zh','z','i','j','k','l','m','n','o','p','r','s','t','u','f','h','ch','c','sh','csh','e','ju','ja','y','', '', ' ', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '+');
		var from = "";
		function convert2EN()
		{
			from = document.getElementById("postTitle").value;
			from = from.toLowerCase();
			var to = "";
			var len = from.length;
			var character, isRus;
			for(var i=0; i < len; i++)
			{
				character = from.charAt(i,1);
				isRus = false;
				for(var j=0; j < rusChars.length; j++)
				{
					if(character == rusChars[j])
					{
						isRus = true;
						break;
					}
				}
				to += (isRus) ? transChars[j] : character;
			}
			document.getElementById("url").value = to;
		}
	</script>
	<?php
	
	
	break;
case 2:
	//auth check
	if (empty($_SESSION['id']))
	{
		echo 'Авторизуйтесь';
		break;
	}
	
	$message = trim($_POST['message']);
	$title = trim($_POST['title']);
	$tags = $_POST['tags'];
	$url = clear_url_tab($_POST['url'], "url");
	
	$poster = new Posting;
	$poster -> newPost($message, $title, $tags, $url);
	break;
}
echo '</div>';
require_once ('../includes/themes/' . $myTheme . '/end.php');
?>